import { contextBridge, ipcRenderer } from 'electron'
contextBridge.exposeInMainWorld('electronAPI', {
  sendMessage: (message) => ipcRenderer.send('message-from-renderer', message),
  onMessage: (callback) =>
    ipcRenderer.on('message-from-main', (event, message) => callback(message)),
  rendererSend: (option, value) => ipcRenderer.send('rendererSend', option, value),
  mainOut: (callback) => ipcRenderer.once('mainOut', (event, message) => callback(message)),
  menuBar: (type) => ipcRenderer.send('menuBar', type)
})

// Custom APIs for renderer

// Use `contextBridge` APIs to expose Electron APIs to
// renderer only if context isolation is enabled, otherwise
// just add to the DOM global.
// if (process.contextIsolated) {
//   try {
//     contextBridge.exposeInMainWorld('electron', electronAPI)
//     contextBridge.exposeInMainWorld('api', api)
//   } catch (error) {
//     console.error(error)
//   }
// } else {
//   window.electron = electronAPI
//   window.api = api
// }
